const Base = require('./base.js');
module.exports = class extends Base {
	constructor(ctx) {
		super(ctx);
		this.receipt = this.model('store/receipt');
	}
	async indexAction() {
		if(this.isGet) {
			return this.display();
		}

		let posts = this.post();

		let where = {};
		if(!think.isEmpty(posts.userid)){
			where.user_id = posts.userid;
		}
		const data = await this.receipt.dataTable(posts, where);
		console.log(JSON.stringify(data))
		return this.json(data);
	}
	
	async detailAction(){
		if(this.isGet) {
			let gets = this.get();			
			let receipt = await this.receipt.findOne(gets.id);
			this.assign("receipt",receipt);
			return this.display();
		}
	}
	
	async dealAction(){
		let posts = this.post();		
		let user = await this.session("user");
		let data = {
			status: posts.status,
			admin_id: user.id,
			remark:posts.remark
		};
		if(posts.status == 1){
			data.pay_time = new Date().valueOf();
		}
		await this.receipt.setOne(posts.id,data);
		return this.success();
		
	}
};